﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Manage_stuexam : ManagePageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSearch.Text = Resources.labels.search;
        if (!IsPostBack)
        {
            binddept();
            bind();
        }
    }

    private void binddept()
    {
        List<Exam.Core.Model.Department> DeptList = new Exam.Core.DAL.Department().getDepartmentAllList(isTheMe.DepartmentID);
        foreach(Exam.Core.Model.Department dept in DeptList){
            ddltept.Items.Add(new ListItem(dept.DepartmentName.Trim(), dept.DepartmentID.Trim()));
        }
        ddltept.Items.Insert(0, new ListItem(Resources.labels.alldepartment, isTheMe.DepartmentID.Trim(',').Trim()));
    }

    private void bind()
    {

        string deptid = this.ddltept.SelectedValue.Trim();
        string keyword = this.keywordTb.Text.Trim();

        int pagesize = AspNetPager1.PageSize;
        int page = AspNetPager1.CurrentPageIndex - 1; //GetPageIndex();
        int size = new Exam.Core.DAL.Student().getSize(
                deptid,
                keyword);
        AspNetPager1.RecordCount = size;
        List<Exam.Core.Model.Student> list = new Exam.Core.DAL.Student().getStudentListByPage(
                pagesize,
                page,
                deptid,
                keyword
            );
        rp.DataSource = list;
        rp.DataBind();
        
    }
    protected string getDepart(string id)
    {
        string result = "";
        int b = 0;
        string[] list = id.Trim(',').Split(',');
        foreach (ListItem item in ddltept.Items)
        {
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i].Trim() == item.Value.Trim())
                {
                    result += item.Text.Trim() + "，";

                }
            }
        }
        return result.Trim('，');
    }

    protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            
        }

    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bind();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        bind();
    }

}